<html>
<head>
  <title> Always on Visible Workspace Test - window #1 </title>
</head>
<body style="background-color:rgba(0,0,0,0);">
<div id="test-contents">
  <h3>Window #1</h3>
  <p>This window is <span id="workspaces_status">visible only on this workspace</span></p>
  <div>
    <a href="" id="visible-on-all-workspaces">Visible on all workspaces</a>
    <p>Makes the window visible on all workspaces simultaneously.</p>
  </div>
  <div>
    <a href="" id="only-on-this-desktop">Only on this workspace</a>
    <p>Makes the window visible only on this workspace.</p>
  </div>
  <p id="output"></p>
</div>
<script>

if (Window.canSetVisibleOnAllWorkspaces()) {
  testSetVisibleOnAllWorkspaces();
} else {
  notSupported();
}

function testSetVisibleOnAllWorkspaces() { 
  var gui = require('nw.gui');
  var win = gui.Window.get();

  function setVisibleOnAllWorkspaces(all_workspaces){
    win.setVisibleOnAllWorkspaces(all_workspaces);

    updateStatusText(all_workspaces);

    document.getElementById("output").innerHTML += 
      'called Window.setVisibleOnAllWorkspaces(' + all_workspaces + ');<br/>\n';
  }

  function updateStatusText(all_workspaces) {
    var statusEl = document.getElementById('workspaces_status');
    var statusText = all_workspaces ? 'visible on all workspaces' : 'visible only on this workspace';
    statusEl.innerText = statusText;
  }

  updateStatusText(gui.App.manifest.window['visible-on-all-workspaces']);

  document.getElementById('visible-on-all-workspaces').onclick = function (e) { setVisibleOnAllWorkspaces(true); e.preventDefault(); };
  document.getElementById('only-on-this-desktop').onclick = function (e) { setVisibleOnAllWorkspaces(false); e.preventDefault(); };

  gui.Window.open('./index2.html', {
    position: 'center',
    x: win.x+20,
    y: win.y+20
  });
}

function notSupported() {
  document.getElementById('test-contents').innerHTML = 
    "Test not supported on this platform";
}

</script>  
</body>
</html>
